package com.kws.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.kws.common.core.domain.R;
import com.kws.system.domain.info.QueryKnowledgeBaseInfo;
import com.kws.system.domain.vo.CreateKnowledgeBaseRq;
import com.kws.system.domain.vo.UpdateKnowledgeBaseRq;
import com.kws.system.service.SysKnowledgeBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <b>SysKnowledgeBaseController</b>
 *
 * @description: SysKnowledgeBaseController <br>
 * @date: 2024/11/4 15:00 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "知识库管理模块")
@RestController
public class SysKnowledgeBaseController {
    private static final Logger logger = LoggerFactory.getLogger(SysKnowledgeBaseController.class);

    @Autowired
    private SysKnowledgeBaseService sysKnowledgeBaseService;

    @ApiOperation("分页查询知识库列表")
    @GetMapping("/query/knowledgeBase/page")
    public R<Page<QueryKnowledgeBaseInfo>> queryKnowledgeBasePage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                                  @RequestParam(required = false) String content){
        Page<QueryKnowledgeBaseInfo> pageInfo = sysKnowledgeBaseService.queryKnowledgeBasePage(pageNum,pageSize,content);
        return R.ok(pageInfo);
    }

    @ApiOperation("新增知识库数据")
    @PostMapping("/create/knowledgeBase")
    public R createKnowledgeBase(@RequestBody CreateKnowledgeBaseRq rq){
        boolean status = sysKnowledgeBaseService.createKnowledgeBase(rq);
        return R.ok(status);
    }

    @ApiOperation("根据ID查询知识库详情")
    @GetMapping("/query/knowledgeBase/byId")
    public R<QueryKnowledgeBaseInfo> queryKnowledgeBaseById(@RequestParam Long id){
        QueryKnowledgeBaseInfo info = sysKnowledgeBaseService.queryKnowledgeBaseById(id);
        return R.ok(info);
    }

    @ApiOperation("根据ID修改知识库信息")
    @PostMapping("/update/knowledgeBase")
    public R updateKnowledgeBaseById(@RequestBody UpdateKnowledgeBaseRq rq){
        boolean status = sysKnowledgeBaseService.updateKnowledgeBaseById(rq);
        return R.ok(status);
    }

    @ApiOperation("根据ID删除知识库信息")
    @GetMapping("/delete/knowledgeBase/byId")
    public R deleteKnowledgeBaseById(@RequestParam Long id){
        boolean status = sysKnowledgeBaseService.deleteKnowledgeBaseById(id);
        return R.ok(status);
    }
}
